package wolftrace_company.study_android_ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import wolftrace_company.study_android_ui.R;
import wolftrace_company.study_android_ui.bean.User;

/**
 * Created by SimpleTonOne on 2018/4/1.
 */

public class MyListAdapter extends BaseAdapter {

    private List<User> list;
    private LayoutInflater layoutInflater;

    public MyListAdapter(List<User> list, Context context) {
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
    }
    public final class ListItemView{
        public TextView textView1,textView2,textView3,textView4,textView5,textView6;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if(convertView==null){
            listItemView = new ListItemView();
            convertView = layoutInflater.inflate(R.layout.info_items,null);
            listItemView.textView1 = convertView.findViewById(R.id.username);
            listItemView.textView2 = convertView.findViewById(R.id.userage);
            listItemView.textView3 = convertView.findViewById(R.id.userclass);
            listItemView.textView4 = convertView.findViewById(R.id.usertall);
            listItemView.textView5 = convertView.findViewById(R.id.usertel);
            listItemView.textView6 = convertView.findViewById(R.id.userident);
            convertView.setTag(listItemView);
        }else{
            listItemView = (ListItemView) convertView.getTag();

        }
        User user = list.get(position);
        listItemView.textView1.setText(user.getName());
        listItemView.textView2.setText(user.getAge());
        listItemView.textView3.setText(user.getUserClass());
        listItemView.textView4.setText(user.getTel());
        listItemView.textView5.setText(user.getTall());
        listItemView.textView6.setText(user.getIdent());
        return convertView;

    }
}
